package com.sc.weixin.consultComment;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.sc.dal.common.pagination.PaginationBean;
import com.sc.dal.mapper.consultComment.ConsultCommentMapper;
import com.sc.dal.mapper.goods.GoodsMapper;
import com.sc.dal.model.consultComment.ConsultComment;
import com.sc.dal.model.member.Member;
import com.sc.dal.model.order.Order;
import com.sc.service.consultComment.ConsultCommentService;
import com.sc.service.goods.GoodsService;
import com.sc.service.order.OrderService;
import com.sc.util.adapter.ConfigBeanAdapter;
import com.sc.util.data.Common;
import com.sc.util.data.Constants;
import com.sc.util.data.DataUtil;
import com.sc.util.data.FileUtil;
import com.sc.util.data.SessionContainer;
import com.sc.util.exception.ExceptionEnum;
import com.sc.util.exception.ScBizException;
/**
 * 咨询、评论、浏览管理
 * @author xiongyong
 * @2017.4.15 9:20:34 AM
 * 
 */
@Controller
@RequestMapping(value="/consultComment")
public class ConsultCommentController {
	private final Logger logger = LoggerFactory.getLogger(ConsultCommentController.class); 
	
	@Autowired
	private ConsultCommentService consultCommentService;
	
	@Autowired
	private OrderService orderService;
	
	@Autowired
	private GoodsService goodsService;
	
	/****
	 * 初始化商品详情--全部评价信息页面
	 * @param request
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/initGoodsComment")
	private Object initGoodsComment(HttpServletRequest request, Integer currPage, Integer pageSize){
		ModelAndView mav = new ModelAndView("/consultComment/allEvaluate");
		int totalRecords = 0;	//总记录数
		int totalPage = 0;		//总页数
		pageSize=20;
		List<Map<String, Object>> resultList = null;
		String type = request.getParameter("type");
		try {
			Map<String,Object> paramMap = new HashMap<String,Object>();
			paramMap.put("type", type);
			String goodsId = request.getParameter("goodsId");
			if(goodsId!=null && !"".equals(goodsId)){
				paramMap.put("goodsId", goodsId);
				mav.addObject("goodsId", goodsId);
			}
			//我的足迹不等3，如其下判断
			if(!"3".equals(type)){
				String status = request.getParameter("status");
				//status【咨询状态：0：全部数据 1：已回复  2：未回复  】【评价状态：0：全部 1：差评  2：中评  3：好评  4：有图评价】 
				if(status!=null && !"".equals(status)){
					paramMap.put("status", status);
				}else{
					paramMap.put("status", null);
				}
			}else{
				paramMap.put("status", "status");
			}
			
			PaginationBean<Map<String,Object>> pagination = this.consultCommentService.getPagingDatas(paramMap, currPage, pageSize, "count","select",ConsultCommentMapper.class);
			resultList = pagination.getPageList();//返回数据
			
			totalRecords = pagination.getTotalRecords();//返回行数
			totalPage = pagination.getTotalPage();
			int currentPage = pagination.getCurrentPage();//获取当前页数
			mav.addObject("totalPage", totalPage);
			mav.addObject("totalRecords", totalRecords);
			mav.addObject("resultList", resultList);
			mav.addObject("currentPage", currentPage);
			mav.addObject("evaluateFlag","false");
		} catch (Exception e) {
			logger.error("查询咨询、评价信息数据异常"+e);
			throw new ScBizException("查询咨询、评价信息数据异常！", e);
		}
		return mav;
	}
	
	
	/**
	 * 针对商品评价【查询单个商品的全部评价信息】
	 * 根据条件查询咨询、评价、浏览内容数据【未拦截用户必须登录查询的结果信息】
	 * type : 1、咨询内容 2、评价晒单 3、我的足迹',
	 * @param request
	 * @return
	 */
	@RequestMapping(value="queryConsultAll")
	@ResponseBody
	public Object queryConsultAll(HttpServletRequest request,Integer currPage, Integer pageSize){
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		int totalRecords = 0;	//总记录数
		int totalPage = 0;		//总页数
		pageSize = 20;
		List<Map<String, Object>> resultList = null;	
		String type = request.getParameter("type");
		if(type==null || "".equals(type)){
			logger.warn("type查询参数为空！");
		}else{
			try {
				Map<String,Object> paramMap = new HashMap<String,Object>();
				paramMap.put("type", type);
				String goodsId = request.getParameter("goodsId");
				if(goodsId!=null && !"".equals(goodsId)){
					paramMap.put("goodsId", goodsId);
				}
				//我的足迹不等3，如其下判断
				if(!"3".equals(type)){
					String status = request.getParameter("status");
					//status【咨询状态：0：全部数据 1：已回复  2：未回复  】【评价状态：0：全部 1：差评  2：中评  3：好评  4：有图评价】 
					if(status!=null && !"".equals(status)){
						paramMap.put("status", status);
					}else{
						paramMap.put("status", null);
					}
				}else{
					paramMap.put("status", "status");
				}
				
				PaginationBean<Map<String,Object>> pagination = this.consultCommentService.getPagingDatas(paramMap, currPage, pageSize, "count","select",ConsultCommentMapper.class);
				resultList = pagination.getPageList();//返回数据
				/**组合追加的评论数据***/
				for (int i = 0; i < resultList.size(); i++) {
					ConsultComment comment = (ConsultComment) resultList.get(i);
					Map<String, Object> map = new HashMap<String, Object>();
					Integer id = comment.getId();
					map.put("id", id);
					if(goodsId!=null && !"".equals(goodsId)){
						map.put("goodsId", goodsId);
					}
					List<ConsultComment> idList = consultCommentService.selectParentList(map);
					comment.setChildrenList(idList);
				}
					totalRecords = pagination.getTotalRecords();//返回行数
					totalPage = pagination.getTotalPage();
					int currentPage = pagination.getCurrentPage();//获取当前页数
					resultMap.put("totalPage",totalPage);
					resultMap.put("totalRecords",totalRecords);
					resultMap.put("resultList", resultList);
					resultMap.put("currentPage", currentPage);
					resultMap.put("evaluateFlag","false");
			} catch (Exception e) { 
				logger.error("查询咨询、评价信息数据异常"+e);
				throw new ScBizException("查询咨询、评价信息数据异常！", e);
			}
		}
		return resultMap;
	}
	
	/**
	 * 针对个人中心【查询个人用户的咨询，评价、足迹】
	 * 根据条件查询咨询、评价、浏览内容数据 【拦截用户必须登录查询的结果信息】
	 * type : 1、咨询内容 2、评价晒单 3、我的足迹',
	 * @param request
	 * @return
	 */
	@RequestMapping(value="queryConsult")
	@ResponseBody
	public Object queryConsult(HttpServletRequest request,Integer currPage, Integer pageSize){
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		int totalRecords = 0;	//总记录数
		int totalPage = 0;		//总页数
		pageSize = 20;
		List<Map<String, Object>> resultList = null;
		String type = request.getParameter("type");
		if(type==null || "".equals(type)){
//			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_PARAM);
			logger.warn("type查询参数为空！");
		}else{
			try {
				Map<String,Object> paramMap = new HashMap<String,Object>();
				paramMap.put("type", type);
				String goodsId = request.getParameter("goodsId");
				if(goodsId!=null && !"".equals(goodsId)){
					paramMap.put("goodsId", goodsId);
				}
				//获取会员ID
				Member member = SessionContainer.getSessionMember(request);
				if(member != null){
					paramMap.put("creater", member.getmId());
				}
				//我的足迹不等3，如其下判断
				if(!"3".equals(type)){
					String status = request.getParameter("status");
					//status【咨询状态：0：全部数据 1：已回复  2：未回复  】【评价状态：0：全部 1：差评  2：中评  3：好评  4：有图评价】 
					if(status!=null && !"".equals(status)){
						paramMap.put("status", status);
						//status =4  根据条件查询有图片的数据
						/*}else if(status!=null && !"".equals(status) && "4".equals(status)){
						paramMap.put("filePicture", "");
					//status =0  根据条件查询所有的数据
					}*/
					}else{
						paramMap.put("status", null);
					}
				}else{
					paramMap.put("status", "status");
				}
				
				PaginationBean<Map<String,Object>> pagination = this.consultCommentService.getPagingDatas(paramMap, currPage, pageSize, "count","select",ConsultCommentMapper.class);
				resultList = pagination.getPageList();//返回数据
				/**组合追加的评论数据***/
				for (int i = 0; i < resultList.size(); i++) {
					ConsultComment comment = (ConsultComment) resultList.get(i);
					Map<String, Object> map = new HashMap<String, Object>();
					Integer id = comment.getId();
					map.put("id", id);
					if(goodsId!=null && !"".equals(goodsId)){
						map.put("goodsId", goodsId);
					}
					List<ConsultComment> idList = consultCommentService.selectParentList(map);
					comment.setChildrenList(idList);
				}
				totalRecords = pagination.getTotalRecords();//返回行数
				totalPage = pagination.getTotalPage();
				int currentPage = pagination.getCurrentPage();//获取当前页数
				resultMap.put("totalPage",totalPage);
				resultMap.put("totalRecords",totalRecords);
				resultMap.put("resultList", resultList);
				resultMap.put("currentPage", currentPage);
				resultMap.put("evaluateFlag","true");
			} catch (Exception e) {
				logger.error("查询咨询、评价信息数据异常"+e);
				throw new ScBizException("查询咨询、评价信息数据异常！", e);
			}
		}
		return resultMap;
	}
	
	/****
	 * 初始化商品评价信息页面
	 * @param request
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/initGoodsCousult")
	private Object initGoodsCousult(HttpServletRequest request){
		/*ModelAndView mav = new ModelAndView("/consultComment/consulting");*/
		ModelAndView mav = new ModelAndView("/consultComment/question");
		String goodsId = request.getParameter("goodsId");//商品ID
		String goodsName = request.getParameter("goodsName");
		String type = request.getParameter("type"); //类型
//		String creater = request.getParameter("creater");
		mav.addObject("goodsId", goodsId);
		mav.addObject("creater", "会员测试");
		mav.addObject("type", type);
		mav.addObject("goodsName", goodsName);
		return mav;
	}
	/**
	 * 提交咨询内容
	 * type : 1、咨询内容 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="/addConsult")
	@ResponseBody
	public Object addConsult(HttpServletRequest request) throws UnsupportedEncodingException{
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		try {
			ConsultComment record = new ConsultComment();
			Member member = SessionContainer.getSessionMember(request);
			if(member == null){
				return "/member/loginPre";
			}
			String goodsId = request.getParameter("goodsId");
			if(Common.isNotEmpty(goodsId))record.setGoodsId(new Integer(goodsId));
			String consultContent = request.getParameter("consultContent");
			if(Common.isNotEmpty(consultContent))record.setConsultContent(consultContent);
			
			record.setType(Constants.TYPE_A); //咨询内容
			record.setIsDelete(Constants.IS_DELETEA); //状态：是否删除
			record.setStatus("2");
			record.setCreater(member.getmId());
			record.setCreateTime(new Date()); //创建时间
			int j = consultCommentService.insertByConsultComment(record);
			if(j>0){
				DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_SUCCESS);
				logger.warn("数据保存成功！");
//				return "success";
				return resultMap;
			}else{
				DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
				logger.warn("数据保存出错！");					
				return resultMap;
			}
		} catch (Exception e) {
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
			logger.error("提交咨询内容数据异常"+e);
			throw new ScBizException("提交咨询内容数据异常！", e);
		}
	}
	
	/**
	 * 提交评价内容
	 * type : 2、评价内容
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="/addCommont")
	@ResponseBody
	public Object addCommont(HttpServletRequest request) throws UnsupportedEncodingException{
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		try {
			Member member = SessionContainer.getSessionMember(request);
			if(member == null){
				resultMap.put("sessionValid", true); //会话失效
    			return resultMap;
			}
			ConsultComment record = new ConsultComment();
			String goodsId = request.getParameter("goodsId");
			if(Common.isNotEmpty(goodsId))record.setGoodsId(new Integer(goodsId));
			String consultContent = request.getParameter("consultContent");
			if(Common.isNotEmpty(consultContent))record.setConsultContent(consultContent);
			if(Common.isNotEmpty(request.getParameter("commentId")))record.setParentId(new Integer(request.getParameter("commentId")));
			record.setType(Constants.TYPE_B); //评价内容
			record.setIsDelete(Constants.IS_DELETEA); //状态：是否删除
			String goodsSatisfaction = request.getParameter("goodsSatisfaction");
			if(goodsSatisfaction!=null && "5".equals(goodsSatisfaction)){
				record.setStatus("3");  //好评
			}else if(goodsSatisfaction!=null && ("4".equals(goodsSatisfaction)||"3".equals(goodsSatisfaction))){
				record.setStatus("2");  //中评
			}else if(goodsSatisfaction!=null && ("2".equals(goodsSatisfaction)||"1".equals(goodsSatisfaction))){
				record.setStatus("1");  //差评
			}
			record.setGoodsSatisfaction(goodsSatisfaction);
			String logisticsScore = request.getParameter("logisticsScore");
			record.setLogisticsScore(logisticsScore);
			record.setServiceScore(request.getParameter("serviceScore"));
			String orderId = request.getParameter("orderId");
			record.setOrderId(orderId);
			record.setSpecInfo(request.getParameter("goodsSkuInfo"));
			record.setFilePicture(request.getParameter("filePicture"));
			record.setFilePicture2(request.getParameter("filePicture2"));
			record.setFilePicture3(request.getParameter("filePicture3"));
			record.setCreater(member.getmId());
			record.setCreateTime(new Date()); //创建时间
			int j = consultCommentService.insertByConsultComment(record);
			if(j>0){
				DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_SUCCESS);
				logger.warn("数据保存成功！");
				if (resultMap.get("resultSuccess") != null&& resultMap.get("resultSuccess").toString().equals("true")) {
					this.orderService.updateOrderAndOrderDetailCommentStatus(orderId, new Integer(goodsId));
				}
				return resultMap;
			}else{
				DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
				logger.warn("数据保存出错！");					
				return resultMap;
			}
		} catch (Exception e) {
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
			logger.error("提交评价信息数据异常"+e);
			throw new ScBizException("提交评价信息数据异常！", e);
		}
	}
	
	
	/****
	 * 个人中心
	 * 初始化  我的评价晒单
	 * 根据type 
	 * @param request
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/allEvaluate")
	private Object allEvaluate(HttpServletRequest request,Integer currPage,Integer pageSize){
		ModelAndView mav = new ModelAndView("/consultComment/allEvaluate");
		int totalRecords = 0;	//总记录数
		int totalPage = 0;		//总页数
		List<Map<String, Object>> resultList = null;
		String type = request.getParameter("type");
		try {
			Map<String,Object> paramMap = new HashMap<String,Object>();
			Member member = SessionContainer.getSessionMember(request);
			if(member != null){
				mav.addObject("member", member);
				paramMap.put("creater", member.getmId());
			}
			paramMap.put("type", type);
			String goodsId = request.getParameter("goodsId");
			if(goodsId!=null && !"".equals(goodsId)){
				paramMap.put("goodsId", goodsId);
				mav.addObject("goodsId", goodsId);
			}
			//我的足迹不等3，如其下判断
			if(!"3".equals(type)){
				String status = request.getParameter("status");
				//status【咨询状态：0：全部数据 1：已回复  2：未回复  】【评价状态：0：全部 1：差评  2：中评  3：好评  4：有图评价】 
				if(status!=null && !"".equals(status)){
					paramMap.put("status", status);
				}else{
					paramMap.put("status", null);
				}
			}else{
				paramMap.put("status", "status");
			}
			
			PaginationBean<Map<String,Object>> pagination = this.consultCommentService.getPagingDatas(paramMap, currPage, pageSize, "count","select",ConsultCommentMapper.class);
			resultList = pagination.getPageList();//返回数据
			
			totalRecords = pagination.getTotalRecords();//返回行数
			totalPage = pagination.getTotalPage();
			int currentPage = pagination.getCurrentPage();//获取当前页数
			mav.addObject("totalPage", totalPage);
			mav.addObject("totalRecords", totalRecords);
			mav.addObject("resultList", resultList);
			mav.addObject("currentPage", currentPage);
			mav.addObject("evaluateFlag","true");
		} catch (Exception e) {
			logger.error("查询咨询、评价信息数据异常"+e);
			throw new ScBizException("查询咨询、评价信息数据异常！", e);
		}
		return mav;
	}
	
	/****
	 * 个人中心
	 * 初始化  我的咨询   、  我的足迹
	 * 根据type 1:咨询    creater :当前用户
	 * @param request
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/initMyConsulting")
	private Object initMyConsulting(HttpServletRequest request,Integer currPage,Integer pageSize){
		ModelAndView mav = null;
		Map<String, Object> paramMap = new LinkedHashMap<String, Object>();
		String type = request.getParameter("type");
		if(type!=null && "1".equals(type)){
			mav = new ModelAndView("/consultComment/myConsulting");
		}else if(type!=null && "3".equals(type))
			mav = new ModelAndView("/consultComment/footprint");
			paramMap.put("status","null");
		int totalRecords = 0;	//总记录数
		int totalPage = 0;		//总页数
		List<Map<String, Object>> resultList = null;
		paramMap.put("type",type);
		Member member = SessionContainer.getSessionMember(request);
		if(member != null){
			mav.addObject("member", member);
			paramMap.put("creater", member.getmId());
		}
		try {
			pageSize = 20;
			PaginationBean<Map<String,Object>> pagination = this.consultCommentService.getPagingDatas(paramMap, currPage, pageSize, "count","select",ConsultCommentMapper.class);
			resultList = pagination.getPageList();//返回数据
			totalRecords = pagination.getTotalRecords();//返回行数
			totalPage = pagination.getTotalPage();
			int currentPage = pagination.getCurrentPage();//获取当前页数
			mav.addObject("totalPage", totalPage);
			mav.addObject("totalRecords", totalRecords);
			mav.addObject("resultList", resultList);
			mav.addObject("currentPage", currentPage);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
	}
	
	
	/****
	 * 删除足迹信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/deleteFootprint")
	@ResponseBody
	public Object deleteFootprint(HttpServletRequest request){
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		try {
			//判断用户是否登录
			Member member = SessionContainer.getSessionMember(request);
			if(member == null){
//				resultMap.put("sessionValid", true); //会话失效
    			return "error";
			}
			int j = 0;
			String id = request.getParameter("id");
			if(Common.isNotEmpty(id)){
				String idTemp[] = id.split(",");
				for (int i = 0; i < idTemp.length; i++) {
					Integer idd = new Integer(idTemp[i]);
					j = consultCommentService.deleteConsult(idd);
				}
				if(j>0){
					return "success";
				}else{
					return "error";
				}
			}
		} catch (Exception e) {
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_SELECT);
			logger.error("查询最近浏览过的商品数据异常"+e);
			throw new ScBizException("查询最近浏览过的商品数据异常！", e);
		}
		return  "error";
	}
	
	
	/****
	 * 个人中心
	 *  我的咨询详细信息
	 * 咨询回复内容
	 * @param request
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/initMyconsultingData")
	private Object initMyconsultingData(HttpServletRequest request){
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
		ModelAndView mav = new ModelAndView("/consultComment/myconsultingData");
		String id = request.getParameter("id");
		if(id==null){
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
			return resultMap;
		}
		ConsultComment consultComment = consultCommentService.selectConsultDetail(new Integer(id));
		mav.addObject("consultComment", consultComment);
		return mav;
	}
	
	
	/**
	 * 上传图片
	 * @Title: addConsultCommentPic
	 * @Description 异步上传订单商品评价图片
	 * @date 2017年5月12日上午12:38
	 * @author LeiJia  
	 * @return Map<String,Object>    返回类型
	 */
	@RequestMapping(value="/addConsultCommentPic")
	@ResponseBody
	public Map<String,Object> addConsultCommentPic(MultipartHttpServletRequest requests,HttpServletRequest request){
		String filePictureT= request.getParameter("filePicture");
		String filePictureT2= request.getParameter("filePicture2");
		String filePictureT3= request.getParameter("filePicture3");
		
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		String commentPath = "imgUrl"; //图片存储相对路径
		List<String> imgUrls=new ArrayList<String>(); //图片相对路径集合
		try{
			if(requests.getFiles("files")  == null){
				DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_PARAM);
				return resultMap;
			}
			 //取出一个list的multipartfile 
	        List<MultipartFile> files = requests.getFiles("imageFiles");  
	        for (int i = 0;i< files.size() ; i++) {  
	        	MultipartFile multipartFile = files.get(i);
	            String imgUrl  =  FileUtil.upload(multipartFile, "filePicture"+i, commentPath, ConfigBeanAdapter.fileSaveAddress);
	            imgUrls.add(imgUrl);
	        } 
	        String filePicture = "",filePicture2="",filePicture3="";
			if(imgUrls!=null && imgUrls.size()==1){
				filePicture = imgUrls.get(0);
				//如第一张照片不为空，保存第二张
				if(filePictureT!=null && !"".equals(filePictureT) && !"1".equals(filePicture) )	
					resultMap.put("filePicture2", filePicture);
				//如第一、二张照片都不为空，保存第三张
				if(filePictureT!=null && !"".equals(filePictureT) && filePictureT2!=null && !"".equals(filePictureT2))
					resultMap.put("filePicture3", filePicture);	
				//当所有的照片为空，保存第一张
				if((filePictureT==null || "".equals(filePictureT)) && (filePictureT2==null || "".equals(filePictureT2)) && (filePictureT3==null || "".equals(filePictureT3)))
					resultMap.put("filePicture", filePicture);
			}
	        if(imgUrls!=null && imgUrls.size() ==2){
	        	filePicture = imgUrls.get(0);
	        	filePicture2=imgUrls.get(1);
	        	resultMap.put("filePicture", filePicture);
	        	resultMap.put("filePicture2", filePicture2);
	        }
	        if(imgUrls!=null && imgUrls.size()==3){
	        	filePicture = imgUrls.get(0);
	        	filePicture2=imgUrls.get(1);
	        	filePicture3=imgUrls.get(2);
	        	resultMap.put("filePicture", filePicture);
	        	resultMap.put("filePicture2", filePicture2);
	        	resultMap.put("filePicture3", filePicture3);
	        }
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_SUCCESS);			
		} catch(Exception e){
			e.printStackTrace();
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
		}
		return resultMap; 
	}
	/**
	 * @title updateConsultComments
	 * @deprecated 订单评价、追加评价图片上传
	 * type : 1、咨询内容 2、评价晒单 3、我的足迹',
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="/updateConsultComments")
	@ResponseBody
	public Map<String, Object>  updateConsultComments(HttpServletRequest request,String param) throws UnsupportedEncodingException{
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();

		try {
			param = URLDecoder.decode(param, "UTF-8");
			Member member = SessionContainer.getSessionMember(request);
			if (param == null) {
				DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_PARAM);
				logger.warn("json的param参数传递出错！");
				return resultMap;
			} else {
				List<ConsultComment> list = JSON.parseArray(param,
						ConsultComment.class);
				String orderId = "";
				if (list != null && list.size() > 0) {
					for (ConsultComment model : list) {
						String type = model.getType();
						if (model == null|| type == null|| "".equals(type) || ("2".equals(type)&& Common.isEmpty(model.getOrderId())) || model.getId() == null) {
							DataUtil.handleResultMap(resultMap,ExceptionEnum.DATA_PARAM);
							return resultMap;
						}
						orderId = model.getOrderId();
						ConsultComment record = this.getByConsultComment(model,member.getmId());
						int j = consultCommentService.updateByPrimaryKeySelective(record);
						if (j > 0) {
							DataUtil.handleResultMap(resultMap,ExceptionEnum.DATA_SUCCESS);
						} else {
							DataUtil.handleResultMap(resultMap,ExceptionEnum.DATA_INSERT);
							return resultMap;
						}
					}
				}
				if (resultMap.get("resultSuccess") != null&& resultMap.get("resultSuccess").toString().equals("true")) {
					// 修改订单评论状态
					Order order = new Order();
					order.setOrderId(orderId);
					order.setIsComment(Constants.OrderDetail.OrderStatus.IS_COMMENTB);
					order.setIsDelete(Constants.IS_DELETEA);
					orderService.updateOrder(order);
				}
			}
		} catch (Exception e) {
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
		}
		return resultMap;
	}
	
	
	
	/**
	 * 提交咨询内容、评价内容数据
	 * type : 1、咨询内容 2、评价晒单 3、我的足迹',
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/addConsultCommentTest")
	@ResponseBody
	public Map<String, Object> addConsultCommentTest(HttpServletRequest request,String param,@RequestParam(value="filePicture", required=false) MultipartFile file){
		String matchPath="imgUrl\\";
		String imgUrl=FileUtil.upload(request, file.getOriginalFilename(), matchPath, ConfigBeanAdapter.fileSaveAddress);
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		return resultMap;
	}
	
	
	/**
	 * 组合咨询、评价对象信息数据
	 * @param model 
	 * @param imgUrl
	 * @param imgUrl2
	 * @param imgUrl3
	 * @return
	 */
	/*public ConsultComment getByConsultComment(ConsultComment model,String imgUrl,String imgUrl2,String imgUrl3){
		String type = model.getType(); //类型：1、咨询内容 2、评价晒单 3、我的足迹
		ConsultComment record = new ConsultComment();
		//咨询内容
		if(type!=null && "1".equals(type)){
			record.setGoodsId(model.getGoodsId());//商品ID
			record.setConsultContent(model.getConsultContent()); //咨询内容
			record.setStatus("2");  //提交状态  0 ：全部数据 ；1：已回复 2：未回复
		//评价内容	
		}else if(type!=null && "2".equals(type)){
			record.setGoodsId(model.getGoodsId()); //商品ID
			record.setOrderId(model.getOrderId());
			record.setSpecInfo(model.getSpecInfo()); //商品规格信息
			//全部   1：差评  2：中评  3：好评
			record.setStatus(model.getStatus());
			//上传1图片
			if(imgUrl!=null && !"1".equals(imgUrl)){
				record.setFilePicture(imgUrl);
			}
			//上传2图片
			if(imgUrl2!=null && !"1".equals(imgUrl2)){
				record.setFilePicture2(imgUrl2);
			}
			//上传3图片
			if(imgUrl3!=null && !"1".equals(imgUrl3)){
				record.setFilePicture3(imgUrl3);
			}
			record.setGoodsSatisfaction(model.getGoodsSatisfaction()); //商品评分
			record.setConsultContent(model.getConsultContent()); //评价内容
			record.setLogisticsScore(model.getLogisticsScore()); //物流评分
			record.setServiceScore(model.getServiceScore()); //服务评分
			
		//足迹信息
		}else{
			record.setGoodsId(model.getGoodsId());//商品ID
		}
		record.setType(model.getType()); //类型
		record.setCreater(model.getCreater()); //创建人
		record.setCreateTime(new Date());
		return record;
	}*/
	
	
	
	//封装评论信息
	public ConsultComment getByConsultComment(ConsultComment model,String memberId){
		ConsultComment record = new ConsultComment();
		record.setId(model.getId());
		//评价内容
		record.setGoodsId(model.getGoodsId()); //商品ID
		record.setOrderId(model.getOrderId());
		record.setSpecInfo(model.getSpecInfo()); //商品规格信息
		//全部   1：差评  2：中评  3：好评
		record.setStatus(model.getStatus());			
		record.setGoodsSatisfaction(model.getGoodsSatisfaction()); //商品评分
		record.setConsultContent(model.getConsultContent()); //评价内容
		record.setLogisticsScore(model.getLogisticsScore()); //物流评分
		record.setServiceScore(model.getServiceScore()); //服务评分	
		record.setType(model.getType()); //类型：1、咨询内容 2、评价晒单 3、我的足迹
		record.setModifier(memberId); //创建人
		record.setModifyTime(new Date());
		return record;
	}
	
	/**
	 * 测试
	 * @param args
	 */
	@RequestMapping(value="testMain")
	@ResponseBody
	public Object testMain(HttpServletRequest request,Integer currPage, Integer pageSize){
		Map<String, Object> goodsMap =new HashMap<String, Object>();
		List<Map<String, Object>> resultList = null;
		int totalRecords = 0;
		int totalPage = 0;
		pageSize = 10;
		//参数
		Map<String,Object> paramMap = new LinkedHashMap<String,Object>();
		
		PaginationBean<Map<String, Object>> paginationBean;
		try {
			paginationBean = this.goodsService.getPagingDatas(paramMap, currPage, pageSize, "count", "selectList", GoodsMapper.class);
			resultList = paginationBean.getPageList();
			totalRecords = paginationBean.getTotalRecords();
			totalPage = paginationBean.getTotalPage();
			int currentPage = paginationBean.getCurrentPage(); //获取当前页数
			int beginIndex = paginationBean.getBeginIndex();  //当前索引
			goodsMap.put("resultList", resultList); 
			goodsMap.put("totalRecords", totalRecords);  // 总条数
			goodsMap.put("totalPage", totalPage); //总页数
			goodsMap.put("currentPage", currentPage); //当前的页数
			goodsMap.put("beginIndex", beginIndex);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return goodsMap;
	}
	
	/****
	 * 测试上传
	 * @return
	 */
	@RequestMapping(value="/test")
	public Object test(){
		return "/consultComment/uptest";
	}
	/****
	 * 测试上传
	 * @return
	 */
	@RequestMapping(value="/upTest")
	@ResponseBody
	public Object upTest(MultipartHttpServletRequest requests,HttpServletRequest request){
		List<String> imgUrls=new ArrayList<String>(); //图片相对路径集合
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();	
		String commentPath = "imgUrl"; //图片存储相对路径
		try{
			if(requests.getFiles("files")  == null){
				return null;
			}
			 //取出一个list的multipartfile 
	        List<MultipartFile> files = requests.getFiles("myfiles");  
	        for (int i = 0;i< files.size() ; i++) {  
	        	MultipartFile multipartFile = files.get(i);
	            String imgUrl  =  FileUtil.upload(multipartFile, "filePicture"+i, commentPath, ConfigBeanAdapter.fileSaveAddress);
	            imgUrls.add(imgUrl);
	        } 
			System.out.println("上传成功！！！！！！！！");
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_SUCCESS);			
		} catch(Exception e){
			e.printStackTrace();
			DataUtil.handleResultMap(resultMap, ExceptionEnum.DATA_INSERT);
		}
		return "001"; 
	}


}
